package com.cqut.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cqut.service.IFollowManagerService;
import com.cqut.dao.FollowManagerMapper;
import com.cqut.util.SqlUtil;
import com.cqut.model.FollowManager;

@Service
public class FollowManagerService implements IFollowManagerService {
    @Resource(name="followManagerMapper")
    private FollowManagerMapper followManagerMapper;

    @Override
    public boolean save(FollowManager followManager) {
    	String followId = String.valueOf(System.currentTimeMillis());
    	followManager.setFollowId(followId);
        return followManagerMapper.insert(followManager) > 0;
    }

    @Override
    public boolean update(FollowManager followManager) {
        return followManagerMapper.updateByPrimaryKeySelective(followManager) >= 0;
    }

    @Override
    public boolean delete(String followId) {
        return followManagerMapper.deleteByPrimaryKey(followId) > 0;
    }

    @Override
    public boolean batchDelete(String[] primaryKeys) {
        return followManagerMapper.deleteByPrimaryKeys(primaryKeys) > 0;
    }

    @Override
    public FollowManager findModel(String followId) {
        return followManagerMapper.selectByPrimaryKey(followId);
    }

    @Override
    public FollowManager findModel(String followId, String[] parameters) {
        return followManagerMapper.findModel(followId, SqlUtil.formatParameters(parameters));
    }

    public Map<String, Object> findMap(String followId) {
        String[][] parameters = {{"follow_id", "followId"}, {"user_id", "userId"}, {"follow_time", "followTime"}};
        return this.findMap(followId, parameters);
    }

    public Map<String, Object> findMap(String followId, String[][] parameters) {
        return followManagerMapper.findMap(followId, SqlUtil.formatParametersForAlias(parameters));
    }

    @Override
    public List<FollowManager> loadModels() {
        return this.loadModels(null, null, null, null, -1, -1);
    }

    @Override
    public List<FollowManager> loadModels(String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return this.loadModels(null, condition, values, order, sort, curPage, limit);
    }

    @Override
    public List<FollowManager> loadModels(String[] parameters, String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return followManagerMapper.loadModels(SqlUtil.formatParameters(parameters), SqlUtil.fillCondition(condition, values), order, sort, SqlUtil.getOffset(curPage, limit), limit);
    }

    @Override
    public List<Map<String, Object>> loadMaps() {
        String[][] parameters = {{"follow_id", "followId"}, {"user_id", "userId"}, {"follow_time", "followTime"}};
        return this.loadMaps(parameters, null, null, null, null, -1, -1);
    }

    @Override
    public List<Map<String, Object>> loadMaps(String condition, Object[] values, String order, String sort, int curPage, int limit) {
        String[][] parameters = {{"follow_id", "followId"}, {"user_id", "userId"}, {"follow_time", "followTime"}};
        return this.loadMaps(parameters, condition, values, order, sort, curPage, limit);
    }

    @Override
    public List<Map<String, Object>> loadMaps(String[][] parameters, String condition, Object[] values, String order, String sort, int curPage, int limit) {
        return followManagerMapper.loadMaps(SqlUtil.formatParametersForAlias(parameters), SqlUtil.fillCondition(condition, values), order, sort, SqlUtil.getOffset(curPage, limit), limit);
    }

    @Override
    public long count() {
        return this.count(null, false);
    }

    @Override
    public long count(String condition, Object[] values) {
        return this.count(null, condition, values, false);
    }

    @Override
    public long count(String[] parameters, boolean isDistinct) {
        return this.count(parameters, null, null, isDistinct);
    }

    @Override
    public long count(String[] parameters, String condition, Object[] values, boolean isDistinct) {
        return followManagerMapper.count(SqlUtil.formatParameters(parameters), SqlUtil.fillCondition(condition, values), isDistinct);
    }

}
